package com.gjy.leetcode;

import org.junit.jupiter.api.Test;

/**
 * 344. 反转字符串
 *
 * @author 宫静雨
 * @version 1.0
 * @since 2023-01-06 09:25:12
 */
public class A344 {

    @Test
    public void test1() {
        char[] s = {'H','a','n','n','a','h'};
        reverseString(s);
        System.out.println(s);
    }

    public void reverseString(char[] s) {
        int l = 0, r = s.length - 1;
        while (l < r) {
            s[l] = (char) (s[l] ^ s[r]);
            s[r] = (char) (s[l] ^ s[r]);
            s[l] = (char) (s[l] ^ s[r]);
            l++;
            r--;
        }
    }
}
